﻿<?php
session_start();
require('conn.php');
require('functions.php');
//全站访问
if($config['fangwen']==4){
	exit('网站正在更新');
}	
$ip=GetIP();
$day=date("Y-m-d",time());
$time=time();
if($_SESSION['login']==1){
	_location("ucenter.php",301);
	exit;
}

//登录验证
if($_POST){
	$phone=guolv(trim($_POST['phone']));
	$password=guolv(trim($_POST['password']));
	$save=guolv(trim($_POST['save']));
	//$code=guolv(trim($_POST['code']));
	if(is_phone($phone)==false){
		echo "<script>alert('请输入正确的手机号');location.href='login.php'</script>";
		exit;
	}
	if($password==''){
		echo "<script>alert('请输入密码');location.href='login.php'</script>";
		exit;		
	}	
	// if($code!==$_SESSION['code']){
		// echo "<script>alert('验证码错误，请重新输入');location.href='login.php'</script>";
		// exit;			
	// }
	$row=$mysql->query("select * from `userdata` where `phone`='{$phone}' and `pass`='{$password}' limit 1");
	if($row){
		//登录赠送金额
		$row_login_ip=$mysql->query("select * from `refererdata` where `uid`='{$row[0]['id']}' and `aid`='0' and `day`='{$day}' limit 1");
		if(!$row_login_ip){
			$mysql->query("insert into `refererdata` values(null,'{$row[0]['id']}','0','ID：{$row[0]['id']}用户登录','','{$config['daysong']}','','','{$ip}','{$day}','{$time}')");
			//加钱
			$mysql->query("update `userdata` set `money`=`money`+'{$config['daysong']}' where `id` in({$row[0]['id']}) limit 1");					
		}
        
     
		//保存账号密码，保存一天
		if($save==1){
			setcookie('_phone',$phone,time()+3600*24);
			setcookie('_password',$password,time()+3600*24);
            setcookie('_save',$save,time()+3600*24);
		}else{
     
        setcookie('_phone',$name,time()-3600*24);
unset($_COOKIE['_phone']);
setcookie('_password',$password,time()-3600*24);
unset($_COOKIE['_password']);
setcookie('_save',$save,time()-3600*24);
        }
		$_SESSION['userdata']=$row[0];
        $_SESSION['nick']=$row['nick'];
		$_SESSION['login']=1;
		_location("{$site}/ucenter.php",301);
		exit;
	}else{
		echo "<script>alert('用户名或密码错误');location.href='login.php'</script>";
		exit;
	}
}
$mysql->__destruct();
$mysql->close();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title>登录 - <?php echo $config['sitename']?></title>
<meta name="keywords" content="<?php echo $config['sitename']?>,登录" />
<meta name="description" content="<?php echo $config['sitename']?>用户登录。">
<link href="Css1/base.css" rel="stylesheet" type="text/css" />
<link href="Css1/header.css" rel="stylesheet" type="text/css" />
<link href="Css1/weiui.css" rel="stylesheet" type="text/css" />
<link href="Css1/login.css" rel="stylesheet" type="text/css" />
<script type=text/javascript > var app="/user" </script>
<script type="text/javascript" src="Scripts1/jquery.min.js"></script>
<script type=text/javascript src="Scripts1/jquery.common.js"></script>



<style>
body{margin:0;}
*{box-sizing:border-box;}
input{font-size: 16px;line-height: 1.25em;outline: 0px none;text-decoration: none;margin:0;}/* .squaredTwo */
.squaredTwo {
  width: 28px;
  height: 28px;
  position: relative;
  margin: 0px auto;
  background: #fcfff4;
  background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
}
.squaredTwo label {
  width: 20px;
  height: 20px;
  cursor: pointer;
  position: absolute;
  left: 4px;
  top: 4px;
  background: -moz-linear-gradient(top, #222222 0%, #45484d 100%);
  background: -webkit-linear-gradient(top, #222222 0%, #45484d 100%);
  background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
  -moz-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
  -webkit-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
  box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
}
.squaredTwo label:after {
  content: '';
  width: 9px;
  height: 5px;
  position: absolute;
  top: 4px;
  left: 4px;
  border: 3px solid #fcfff4;
  border-top: none;
  border-right: none;
  background: transparent;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
  opacity: 0;
  -moz-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
}
.squaredTwo label:hover::after {
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=30);
  opacity: 0.3;
}
.squaredTwo input[type=checkbox] {
  visibility: hidden;
}
.squaredTwo input[type=checkbox]:checked + label:after {
  filter: progid:DXImageTransform.Microsoft.Alpha(enabled=false);
  opacity: 1;
}
</style>
</head>

<body>

 

 

	<form action="login.php" method="post" name="form1">


<div id="content">
<!--<header class="i_header">
<div class="header_c">
<a href="/user" class="big_logo"></a>
</div>
</header>-->
<div class="M_content">
    <ul class="unstyled matrix_ul">
        <li>
            <div class="topic_input">
            <div class="topic_bel"> <i class="ico_phone"></i>
            </div>
            <div class="topic_ipt">
			<input name="phone" value="<?php echo $_COOKIE['_phone']?>" id="username" type="tel" class="btx" placeholder="请输入手机号" tabindex="1" required>
            </div>
            </div>
        </li>
        <li>
            <div class="topic_input">
            <div class="topic_bel"> <i class="ico_p"></i>
            </div>
            <div class="topic_ipt">
			<input type="password" value="<?php echo $_COOKIE['_password']?>"  id="password" name="password" placeholder="请输入密码" tabindex="2" class="btx">
            </div>
            <!-- <div class="switch_buttom">
            <div class="switch_off"></div>
            <div class="switch_on">
            <div class="on_n"></div>
            </div>
            <span>显示</span>
            </div> -->
            </div>
        </li> 
    </ul><div><span  style=" margin-top:-10px">记住用户名和密码</span> <?php if($_COOKIE['_save'] == 1){?>  <input type="checkbox" value="1" id="squaredTwo" class="squaredTwo" name="save" checked />
      <?php }else{($_COOKIE['_save'] == "")?> <input type="checkbox" value="1" class="squaredTwo" id="squaredTwo" name="save"   /><?php }?></div>
    <ul class="error_prompt" id="error_prompt"></ul>
	<a href="javascript:;"  onclick="javascript:login();" class="success button blue WJ_blue">登 录</a>
	<p class="wjmm">
    	<a href="reg.php" style=" text-align:left; width:50%">注册账号</a>
		<a href="goto.php" style="text-align:right; width:50%"></a>
    </p>
</div>

<div class="pop pop1" style="display: none;">
  <p class="error">
        <br />
    </p>
</div>
<script type="text/javascript">

	//提示遮罩背景高度
    window.onload=function(){
        var oPop=document.getElementsByClassName('pop-bg');
        oPop[0].style.height=document.body.offsetHeight+'px';
    } 
	$(function() {
		autoHeight_login();
	});	
	
	//设置password字段的值	
	$('.txt-password').bind('input',function(){
		$('#password').val($(this).val());
	});
	
	//提示窗口
	function errShow(content){
		$('.error').html(content);
		$('.pop1').show();
		setTimeout("errHide()",2000);
	}
	
	//隐藏错误提示
	function errHide(){
		$('.pop1').hide();
		$('.error').text('');
		$("#error").html('');
		;
	}
	
	//登陆提示
	function loginShow(content){
		$('.error').html(content);
		$('.pop1').show();
	}
	
	//点击关闭错误提示
	$('.pop1').live('click',function(){
		errHide();
	})
	
	//点击关闭错误提示
	$('.pop').live('click',function(){
		errHide();
	})
	
	//浏览器记住密码时，jquery取不到输入框中的值，所以直接用js取值
	function checkUsername(){		
		var username = document.getElementById("username").value;
		if(username == ""){
			errShow("请输入手机号");
			return false;
		}else{			
			if (!$("#username").val().match(/^(((1[3|4|5|7|8][0-9]{1}))+\d{8})$/)) {
				errShow("手机号不正确");
				return false;
			} else {
				return true;
			}			
		}
	}

	function checkPassword(){
		var password = document.getElementById("password").value;
		if(password == ""){
			errShow("请输入密码");
			return false;
		} 
		if(password.length <6 || password.length>20){
			errShow("密码不合规则，请重新输入");
			return false;
		}
		return true;
	}
	
	//登陆校验
	function login(){
		if(!loginCheck()){
			return;
		}		
	}
	
	function loginCheck(){	
		  	if(checkUsername() && checkPassword()){
			  document.form1.submit();
	   	}
		return false;
	}

</script>
<div style="display: none;">
</div>
</div>		</form>
</body>
</html>